package com.zdxf.client.controller;

import com.zdxf.client.domain.LogDO;
import com.zdxf.client.domain.SystemInfoDO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;


@RestController
@RequestMapping("/log")
public class LogController {

    /**
     * 获取日志信息
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/readLine")
    public Object readLine(@RequestBody LogDO logDO) throws Exception {
        java.lang.System.out.println(logDO.getPath());
        List<String> lines =  LogCollector.readLastLine(new File(logDO.getPath()),logDO.getNumLastLineToRead());
        String logStr ="";
        for (int i = lines.size() - 1; i >=0; i--) {
            logStr += lines.get(i) + "\r";
        }
        return logStr;
    }

    @PostMapping(value = "/getFile")
    public Object getFile(@RequestBody LogDO logDO)  {
        java.lang.System.out.println(logDO.getPath());
        List<String> lines =  LogCollector.readLastLine(new File(logDO.getPath()));
        String logStr ="";
        for (int i = lines.size() - 1; i >=0; i--) {
            logStr += lines.get(i) + "\r";
        }
        return logStr;
    }

}
